package top.jiangqiang.qianyi.common.utils;


import org.dromara.hutool.core.exception.ValidateException;
import org.dromara.hutool.core.text.StrUtil;

import java.util.function.Predicate;

public class ValidationUtil<T> {
    private final T data;

    private ValidationUtil(T data) {
        this.data = data;
    }

    public static <T> ValidationUtil<T> useData(T data) {
        return new ValidationUtil<>(data);
    }

    public ValidationUtil<T> validate(Predicate<T> predicate, String message) {
        if (!predicate.test(this.data)) {
            throw new ValidateException(StrUtil.format(message, this.data));
        } else {
            return this;
        }
    }

}
